'use strict';

module.exports = app => {
  const { INTEGER, DATE } = app.Sequelize;

  const IdleFavorite = app.model.define('idle_favorite', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    user_id: { type: INTEGER, allowNull: false, comment: '用户ID' },
    item_id: { type: INTEGER, allowNull: false, comment: '物资/设备ID' },
    create_time: { type: DATE, defaultValue: app.Sequelize.fn('NOW') }
  }, {
    tableName: 'idle_favorite',
    timestamps: false,
  });

  // 定义关联关系
  IdleFavorite.associate = function() {
    app.model.IdleFavorite.belongsTo(app.model.IdleItem, { foreignKey: 'item_id' });
  };

  return IdleFavorite;
};
